using System;
using System.Web.Mvc;
using HeadspringExample.Core.Domain.Model;
using HeadspringExample.UI.Helpers;

namespace HeadspringExample.UI.Controllers
{
    public class DefaultController : Controller
    {
        protected AutoMapViewResult AutoMapView<TDestination>(ViewResult viewResult)
        {
            return new AutoMapViewResult(
				viewResult.ViewData.Model.GetType(), 
				typeof(TDestination), 
				viewResult);
        }

		protected FormActionResult<TForm> Form<TForm>(TForm form, ActionResult success)
		{
			var failure = View(form);

			return new FormActionResult<TForm>(form, success, failure);
		}


		#region Other helper methods
		protected XmlResult<T> Xml<T>(T toSerialize)
		{
			return new XmlResult<T>
			{
				ModelToSerialize = toSerialize
			};
		}

		protected ActionResult Query<TDestination>(ViewResult viewResult)
		{
			return viewResult;
		}
		#endregion
    }
}
